package leetcode_201_300;

import java.util.Arrays;

public class LeeCode_268 {
    public static void main(String[] args) {
        System.out.println(missingNumber(new int[]{3, 0, 1}));
        System.out.println(missingNumber(new int[]{0, 1}));
        System.out.println(missingNumber(new int[]{1, 2}));
    }
    private static int missingNumber(int[] nums) {
        Arrays.sort(nums);
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (nums[i] != i){
                return i;
            }
        }
        return n;
       /* int l = 0, r = n - 1;
        while (l < r){
            int m = l + (r - l) / 2;
            if (nums[m] == m){
                l = m + 1;
            }else {
                r = m - 1;
            }
        }
        if (l == 0 || l == n - 1)
            return l + 1;
        return l;*/
    }
}
